package chapter1.deepCopy.src.com.kkb.tz.test;


import java.io.Serializable;


public class Person implements Cloneable , Serializable {
	public String name;
	public int age;
	// transient  public Address address;  //transient 这个关键字将会使 Address 无法被序列化; 导致 使用序列化无法深拷贝此 属性;
	public Address address;

	public Person() {
	}

	public Person(String name, int age) {
		this.name = name;
		this.age = age;
		this.address = new Address();
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		 Person p = (Person) super.clone();
		 //引用类型的属性也要实现拷贝; 其实就是层层拷贝;  有个问题, 如何动态实现??
		 p.address = (Address) address.clone();
		return p;
	}

	public void setAddress(String provinces, String city) {
		address.setAddress(provinces, city);
	}

	public void display(String name) {
		System.out.println(  "name=" + this.name + ", age=" + age + "," + address);
	}

	public String print() {
		return "Person{" +
				"name='" + name + '\'' +
				", age=" + age +
				", address=" + address +
				'}';
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public int  getAge (int i) {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public boolean equals(Object o) {
	 	if (o instanceof  Person){

	 		return this.getName().equals(((Person) o).getName());
		}else{
	 		return false ;
		}


	}


	@Override
	public String toString() {
		return "Person{" +
				"name='" + name + '\'' +
				", age=" + age +
				", address=" + address +
				'}';
	}
}